<template>
    <el-form :model="ruleForm" ref="ruleForm" label-width="100px">
        <el-form-item label="姓名" prop="name">
            <el-input v-model="ruleForm.name"></el-input>
        </el-form-item>
        <el-form-item label="状态" prop="status">
            <el-switch v-model="ruleForm.status" :active-value="1"></el-switch>
        </el-form-item>
        <el-form-item label="特殊资源" prop="major">
            <el-radio-group v-model="ruleForm.major">
                <el-radio label="管理员"></el-radio>
                <el-radio label="普通用户"></el-radio>
            </el-radio-group>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="onSubmit()">立即添加</el-button>
            <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
    </el-form>
</template>

<script>
    export default {
        name: "addUser",
        data() {
            return {
                ruleForm: {}
            };
        },
        methods: {
            onSubmit() {
                this.$http.post('/api/users', this.ruleForm)
                .then(({data, config}) => {
                    console.log(data, config)
                    if (data.code == 200) {
                        this.$message({
                            message: '新增成功',
                            type: 'success'
                        })
                    } else {
                        this.$message({
                            message: '新增失败',
                            type: 'warning'
                        })
                    }
                })
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            }
        }
    }
</script>

<style scoped>

</style>